package com.ff.discounts.component.address

import androidx.lifecycle.viewModelScope
import com.ff.discounts.entity.response.onSuccess
import com.ff.discounts.library.log.HiLog
import com.ff.discounts.model.BaseViewModel
import com.ff.discounts.repository.DefaultNetworkRepository
import com.ff.discounts.util.PreferenceUtil
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.launch

/**
 *
 * @author: 40316
 * @date: 2023-10-29
 */
class AddressViewModel(val style:Int) : BaseViewModel() {
    private val _data = MutableSharedFlow<List<AddressData>>()
    val data: Flow<List<AddressData>> = _data

    fun loadData() {
        viewModelScope.launch(coroutineExceptionHandler) {
            DefaultNetworkRepository.getAddressList().onSuccess(viewModel) {
                _data.emit(it ?: listOf())
            }

        }
    }
}